<?php
use think\Db;
//-----------生成随机卡密-------------------------
function randcard(){

	$key='';
	for($i=1;$i<=4;$i++)
	{
		//97~122是小写的英文字母
        //65~90是大写的
		$key=$key.chr(mt_rand(97,122)).chr(mt_rand(65, 90)).mt_rand(0, 9);
	}
	return $key;
}


//------------数据库插入卡密-----------------
function insertkey($num,$type){
	for($i=1;$i<=$num;$i++)
	{
		$str="insert into vipcard(card,type) value('".randcard()."',".$type.");";
		Db::execute($str);
	}
	return $str;
}


//------------数据库卡密查询--------------------
function querycard($num,$type)
{
	$str='select * from vipcard where type='.$type.' limit '.$num.';';
    return  Db::query($str);
}
//------------查找用户------------------------
function getuserinfo($id)
{
	$info=Db::name('user')->field(['id','username','vip','mark'])->where('id',$id)->find();
	return $info;
}
//-------------保存用户信息--------------------
function saveinfo()
{
	$zhi=request()->post();
	$over=Db::name('user')->where('id',$zhi['id'])->update(['username'=>$zhi['username'],'vip'=>$zhi['vip'],'mark'=>$zhi['mark']]);
	return $over;
}

function notice_save($data)
{
	$redis = new \Redis();
	$redis->connect('127.0.0.1',6379);
	$redis->auth('ruqingnimabi');
	$redis -> set('notice',$data['notice']);
}






































































































































































































